#include<bits/stdc++.h>
using namespace std;
long long t,n,a[220344],cl[220344],ans;
long long hdl(){
    long long res=0,p;
    for(int i=1;i<=n;i++){
        p=i-1;
        while(p>0&&cl[p]^cl[i])p--;
        res+=a[i]*(a[p]==a[i]);
    }return res;
}
void dfs(long long d){
    if(d==n){ans=max(ans,hdl());return;}
    dfs(d+1);
    cl[d+1]=1;
    dfs(d+1);
    cl[d+1]=0;
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>t;
    while(t--){
        ans=0;
        cin>>n;
        for(int i=1;i<=n;i++)cin>>a[i];
        dfs(0);
        cout<<ans<<"\n";
    }
    return 0;
}
